package ipt.capitulo21;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.* ;
public class TercerApplet extends JApplet{
	JButton insertaI,insertaS;
	JTextArea areaTextoI= new JTextArea();
	JTextArea areaTextoS = new JTextArea();
	JPanel panel1,panel2,panel3;
	JScrollPane panelS2,panelS3;
	public void init(){
		Container conte = getContentPane();
		conte.setLayout(new BorderLayout());
		insertaI = new JButton("Superior");
		insertaS = new JButton("Inferior");
		insertaS.addActionListener(new VigilaBotones());
		insertaI.addActionListener(new VigilaBotones());
		panel1 = new JPanel();
		panel2 = new JPanel();
		panel3 = new JPanel();
		panel1.add(insertaS);
		panel1.add(insertaI);
		panel2.setLayout(new 
				BoxLayout(panel2, BoxLayout.Y_AXIS));
		panel3.setLayout(new 
				BoxLayout(panel3, BoxLayout.Y_AXIS));
		panelS2 = new JScrollPane(panel2);
		panel2.add(areaTextoS);
				panelS3 = new JScrollPane(panel3);
		panel3.add(areaTextoI);
		panelS2.setVerticalScrollBar(new JScrollBar());
		panelS3.setVerticalScrollBar(new JScrollBar());
		panelS2.setAutoscrolls(true);
		panelS3.setAutoscrolls(true);
		JSplitPane division = new JSplitPane(
		JSplitPane.VERTICAL_SPLIT,panelS2,panelS3);
		division.setDividerLocation(100);
		conte.add("North",panel1);
		conte.add("Center",division);
	}
	class VigilaBotones implements ActionListener{
		public void actionPerformed(ActionEvent e){
			String texto = e.getActionCommand();
			LeePoesia lP=new LeePoesia();
			try{
				if(texto.equals("Superior")){
					URL urlDoc=new URL(getDocumentBase(),
								"Texto1.txt");
					lP.leePoesia(urlDoc,areaTextoS);
				}else{
					URL urlDoc=new URL(getDocumentBase(),
								"Texto2.txt"); 
					lP.leePoesia(urlDoc,areaTextoI);
				}
			}catch(Exception ex){
				System.out.println("Error en la URL"); 
			}
		}
	}
}
